<?php
/**
 * BD_class
 * function $dnconn, $dbquery, $dbinsret
 */
require_once("config.php");
class DB_c
{
    var $_dbconn = NULL;
    var $_dbquery = NULL;
    var $_dbinsert = NULL;
    var $_dbselect = NULL;
    
    function db_connect($host, $user, $password, $dbname)
    {
        $dbconn = mysql_connect($host, $user, $password);
        if (!$dbconn)
            die('MySQL Connect Error');
        mysql_query("SET NAMES utf-8");
        if (! mysql_select_db($dbname, $dbconn))
            die('MySQL Select DB Error');
        $this->_dbconn = $dbconn;
        return true;
    }
    
    function query($sql)
    {
        if (! $dbquery = mysql_query($sql,$this->_dbconn))
            die('MySQL Query Error');
        $this->_dbquery = $dbquery;
        return $dbquery;
    }
    
    function insert($ins)
    {
        if (! $dbinsert = mysql_query($ins,$this->_dbconn))
            die ('MySQL Insret Error');
        $this->_dbinsert = $dbinsert;
        return $dbinsert;
    }
    
    function select($sel)
    {
        if (! $dbselect = mysql_query($sel,$this->_dbconn))
            die ('MySQL Select tables Error');
        $this->_dbselect = $dbselect;
        return $dbselect;
    }
    
    function fetch_array()
    {
       return mysql_fetch_array($this->_dbquery, MYSQL_ASSOC);
    }

    function get_num_rows()
    {
       return mysql_num_rows($this->_dbquery);
    }

    function get_insert_id()
    {
       return mysql_insert_id($this->_dbconn);
    }
}
?>